﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GridArrayBinding
{
    public partial class SampleForm : Form
    {
        private List<guitar> guiterList = new List<guitar>();
        private CurrencyManager currencyManager = null;	

        public SampleForm()
        {
            InitializeComponent();
        }

        private void SampleForm_Load(object sender, EventArgs e)
        {
            guiterList.Add(new guitar("Gibson", "Les Paul", 1958));
            guiterList.Add(new guitar("Fender", "Jazz Bass", 1964));
            guiterList.Add(new guitar("Guild", "Bluesbird", 1971));

            currencyManager = (CurrencyManager)dataGridView1.BindingContext[guiterList];

            dataGridView1.DataSource = guiterList;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            currencyManager.Position++;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            currencyManager.Position--;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            currencyManager.Position = 0;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            currencyManager.Position = guiterList.Count - 1;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            guiterList[0] = new guitar("Gibson-temp", "Les Paul-temp", 1958);
            //dataGridView1.UpdateCellValue(0, 0);
            dataGridView1.Refresh();
        }
    }
}
